﻿using AutoMapper;
using MediatR;
using S.PurchaseAndSales.Domain.Model;
using S.PurchaseAndSales.Infrastructure.Interface.SalesForm;
using S.PurchaseAndSales.Read.Api.Application.Command.SheepSaleCommand;
using S.PurchaseAndSales.Read.Api.Dto;

namespace S.PurchaseAndSales.Read.Api.Application.CommandHandlers.SheepSaleHandler
{
    public class GetCustomByIdCommandHandler : IRequestHandler<GetCustomByIdCommand, GetCustomByIdDto>
    {
        private readonly ICustomerRepository customerRepository;
        private readonly IMapper mapper;

        public GetCustomByIdCommandHandler(ICustomerRepository customerRepository,IMapper mapper)
        {
            this.customerRepository = customerRepository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 通过客户Id获取客户
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<GetCustomByIdDto> Handle(GetCustomByIdCommand request, CancellationToken cancellationToken)
        {
            CustomerInformationModel customerInformationModel = await customerRepository.GetByIdAsync(request.CustomId);
            GetCustomByIdDto getCustomByIdDto = mapper.Map<GetCustomByIdDto>(customerInformationModel);
            return getCustomByIdDto;
        }
    }
}
